<template>
    <div class="listItems">
        <div class="listItems_top">
            <div class="listItems_top_img">
                <img class="img" v-if="isImg(row?.productImage)" :src="isImg(row?.productImage)" alt="" />
                <img class="img" v-else src="@/assets/home/error.png" alt="" />
                <div class="img_tag" v-if="mechanism() && mechanism()[1].cooperationMode"></div>
            </div>
            <div class="top_box">
                <div class="top_box_title">
                    <div class="title">{{ row?.styleName || '' }}</div>
                    <div :class="{ title_tag: true, ...isStatusColour() }">
                        {{ row?.auditStatus == 0 ? '审批中' : row?.auditStatus == 2 ? '已通过' : row?.auditStatus == 1 ? '已驳回' : '' }}
                    </div>
                </div>
                <div class="top_box_text">{{ row?.sellingPoints || '' }}</div>

                <div class="top_box_date" v-if="row?.auditStatus !== '0'">
                    <div v-if="row?.hmSampleAuditLogVos">{{ row?.hmSampleAuditLogVos[0].auditUserName }}审批</div>
                    <div class="l_line"></div>
                    <div v-if="row?.auditStatus == 2 && row?.hmSampleAuditLogVos">{{ row?.hmSampleAuditLogVos[0].auditPassTime }}</div>
                    <div v-if="row?.auditStatus == 1 && row?.hmSampleAuditLogVos">{{ row?.hmSampleAuditLogVos[0].auditRefuseTime }}</div>
                </div>
                <div class="top_box_date" v-if="row?.auditStatus == 0 && types !== 'deatils'">
                    <div v-if="row?.hmSampleAuditLogVos">{{ row?.hmSampleAuditLogVos[0].requestDeptName }}发起</div>
                    <div class="l_line"></div>
                    <div v-if="row?.hmSampleAuditLogVos">{{ row?.hmSampleAuditLogVos[0].requestTime }}</div>
                </div>
                <div class="top_box_number">
                    <div class="number_one">
                        <span class="one_span">￥</span>{{ isPrice(mechanism() && mechanism()[0]) }}
                    </div>
                    <div class="number_two" v-if="mechanism() && mechanism()[0].cooperationMode === '分佣'">
                        <div class="two_left">佣</div>
                        <div class="two_right">{{ mechanism() && mechanism()[0].commission }}%</div>
                    </div>
                    <div class="number_three">{{ mechanism() &&
                        mechanism()[0].liveStreamingMechanism
                        }}</div>
                </div>
                <div class="top_box_date" v-if="types == 'deatils'">
                    <div v-if="row?.hmSampleAuditLogVos">{{ computedrequestRequestDeptName(row?.hmSampleAuditLogVos) }}发起</div>
                </div>
                <div class="bmkc_box" v-else>
                    <div class="kc">
                        <div class="kc_z">补样数量</div>
                        <div class="dsj" v-if="row?.hmSampleAuditLogVos">{{
                            Number(row?.hmSampleAuditLogVos[0].requestSampleNum) }}</div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue'
import { getEnvValue } from "@/utils/index";
const props = defineProps(['row', 'status', 'isTime', 'types'])

const icon_imgNull = new URL("@/assets/newui/imgNull.jpg", import.meta.url).href;
// 图片路径处理
const isImg = (url: string | null) => {
    if (url) {
        let imgArr = url?.split(',')
        if (imgArr?.length) {
            return `${getEnvValue("VITE_APP_PIC_URL")}${imgArr[0]}?x-oss-process=image/resize,w_300`
        } else {
            return icon_imgNull;
        }
    } else {
        return icon_imgNull
    }
}

// 售价与成本区分
const isPrice = (data: any) => {
    if (data?.cooperationMode === '分佣') {
        return data?.price
    } else {
        return data?.costPrice
    }
}
// 状态颜色区分
const isStatusColour = () => {
    if (props.row?.auditStatus == 0) {
        return { "title_tag_lan": true }
    } else if (props.row?.auditStatus == 2) {
        return { "title_tag_lv": true }
    } else if (props.row?.auditStatus == 1) {
        return { "title_tag_hong": true }
    }
}


// 根据不同部门返回不同的机制
const mechanism = () => {
    return props.row?.hmStockMechanismsList && props.row?.hmStockMechanismsList.length ? props.row?.hmStockMechanismsList : null
}

// 获取最近一次的发起人
const computedrequestRequestDeptName = (row: any) =>{
    const data = row.filter((item:any)=>{
        return item.auditStatus == 0
    })
    return data[0].requestDeptName
}

</script>

<style lang="less" scoped>
.listItems {
    padding: 10px;
    box-sizing: border-box;
    background: #fff;

    .listItems_top {
        display: flex;
        justify-content: center;

        .listItems_top_img {
            margin-right: 10px;
            position: relative;


            .img {
                width: 120px;
                height: 120px;
                background: #E5F0FF;
                border-radius: 5px;
                object-fit: cover;
                vertical-align: middle;
            }

            .img_tag {
                width: 46px;
                height: 22px;
                background-image: url("@/assets/newui/productList/icon_duojizhi@2x.png");
                background-size: 100% 100%;
                border-radius: 2px 0px 2px 0px;
                position: absolute;
                top: 0px;
                left: 0px;
            }
        }

        .top_box {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
            justify-content: space-between;

            .top_box_title {
                display: flex;
                align-items: center;
                justify-content: space-between;

                .title {
                    flex: 0.9;
                    min-width: 0;
                    height: 22px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    font-weight: 500;
                    font-size: 16px;
                    color: #1A1B1C;
                }

                .title_tag {
                    padding: 5px 5px;
                    border-radius: 2px;
                    line-height: 12px;
                    text-align: center;
                    font-weight: 500;
                    font-size: 12px;
                }

                .title_tag_lan {
                    background: #EBF4FF;
                    color: #0094FF;
                }

                .title_tag_lv {
                    background: #E7FDEE;
                    color: #19D11B;
                }

                .title_tag_hong {
                    background: #FDE7E7;
                    color: #FC2540;
                }
            }

            .top_box_text {
                width: 100%;
                display: -webkit-box;
                -webkit-line-clamp: 1;
                -webkit-box-orient: vertical;
                overflow: hidden;
                text-overflow: ellipsis;
                font-weight: 400;
                font-size: 12px;
                color: #8492AD;
                word-break: break-all;
            }

            .top_box_date {
                display: flex;
                align-items: center;
                width: fit-content;
                height: 20px;
                background: #FEF6E2;
                border-radius: 5px;
                font-weight: 400;
                font-size: 12px;
                color: #B5884A;
                line-height: 20px;
                padding: 0 5px;

                .l_line {
                    width: 1px;
                    height: 12px;
                    background-color: #B5884A;
                    margin-left: 5px;
                    margin-right: 5px;
                }
            }

            .top_box_number {
                display: flex;
                align-items: center;

                .number_one {
                    font-weight: 500;
                    font-size: 18px;
                    color: #FC2540;

                    .one_span {
                        font-size: 12px;
                        font-weight: 400;
                    }
                }

                .number_two {
                    margin-left: 10px;
                    height: 16px;
                    background: linear-gradient(136deg, #E9D1A5 0%, #CEA46C 100%);
                    border-radius: 2px;
                    display: flex;

                    .two_left {
                        width: 22px;
                        height: 16px;
                        background: #1B1714;
                        border-radius: 2px;
                        text-align: center;
                        line-height: 16px;
                        font-weight: 400;
                        font-size: 12px;
                        color: #CEA46C;
                    }

                    .two_right {
                        padding: 0 3px;
                        text-align: center;
                        line-height: 16px;
                        font-weight: 500;
                        font-size: 12px;
                        color: #1B1714;
                    }
                }

                .number_three {
                    max-width: fit-content;
                    flex: 1;
                    margin-left: 10px;
                    height: 16px;
                    border-radius: 2px;
                    border: 1px solid #FF5A1A;
                    line-height: 16px;
                    text-align: center;
                    font-weight: 400;
                    font-size: 12px;
                    color: #FF5A1A;
                    padding: 0 5px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }
            }

            .bmkc_box {
                .dsj {
                    font-size: 12px;
                    color: #0094FF;
                    line-height: 20px;
                }

                .kc_z {
                    margin-right: 5px;
                    width: 68px;
                    height: 20px;
                    background: #0094FF;
                    border-radius: 5px;
                    font-size: 12px;
                    color: #FFFFFF;
                    line-height: 20px;
                    text-align: center;
                }

                .kc {
                    display: flex;
                    background: #EBF4FF;
                    border-radius: 5px;
                    padding-right: 5px;
                }

                .bm {
                    width: 0px;
                    max-width: fit-content;
                    flex: 1;
                    font-size: 12px;
                    color: #3F68DB;
                    background: #EBF4FF;
                    border-radius: 5px;
                    padding: 4px 5px;
                    margin-right: 10px;
                }

                align-items: center;
                display: flex;
            }

            .top_box_cont {

                .cont_tag {
                    height: 22px;
                    background: #EBF4FF;
                    border-radius: 2px;
                    display: flex;
                    align-items: center;
                    padding: 0 5px;
                    font-weight: 500;
                    font-size: 12px;
                    color: #0094FF;
                    width: fit-content;

                    .tag_img {
                        width: 12px;
                        height: 12px;
                        margin-right: 5px;
                    }
                }
            }
        }
    }

    .listItems_bottom {
        font-weight: 400;
        font-size: 12px;
        color: #8492AD;
    }
}
</style>